<template>
  <view class="my-tab">
    <!-- 遍历底部导航 -->
    <view
      :class="['tab-item', index === tabIndex ? 'tabActive' : '']"
      @click="handleClick(index)"
      v-for="(i, index) in tabList"
      :key="index"
    >
      <template v-if="i.name !== 'center'">
        <image
          :src="index === tabIndex ? i.active : i.icons"
          class="img"
        ></image>
        <view>{{ i.name }}</view>
      </template>
    </view>

    <!-- 中心导航 -->
    <view
      :class="[
        'addBtn',
        addState ? 'addBtnActive' : '',
        showDiscussionForm || showTeamForm ? 'addBtnHidden' : '',
      ]"
      @click="changeAddState"
      >+</view
    >
    <!-- 创建队伍按钮 -->
    <view
      :class="['create', 'team', addState ? 'teamActive' : '']"
      @click="showTeamForm = true"
      v-show="!showDiscussionForm && !showTeamForm"
    >
      <view :class="['content', addState ? 'contentActive' : '']">
        <image src="../../static/icons/createTeam.png"></image>
        <view>创建队伍</view>
      </view>
    </view>

    <!-- 发起讨论按钮 -->
    <view
      :class="['create', 'comment', addState ? 'commentActive' : '']"
      @click="showDiscussionForm = true"
      v-show="!showDiscussionForm && !showTeamForm"
    >
      <view :class="['content', addState ? 'contentActive' : '']">
        <image src="../../static/icons/createComment.png"></image>
        <view>发起讨论</view>
      </view>
    </view>

    <!-- 发布讨论表单 -->
    <view :class="['createForm', showDiscussionForm ? 'formActive' : '']">
      <DiscussionForm @closeForm="showDiscussionForm = false" />
    </view>

    <!-- 创建队伍表单 -->
    <view
      :class="['createForm', showTeamForm ? 'teamFormActive' : '']"
      style="height: 1200rpx"
    >
      <TeamForm @closeForm="showTeamForm = false" />
    </view>

    <!-- 背景遮罩层 -->
    <view :class="['mask', addState ? 'maskActive' : '']"></view>
  </view>
</template>

<script>
import DiscussionForm from "../detail/DiscussionForm.vue";
import TeamForm from "../detail/TeamForm.vue";
export default {
  name: "MyTabBar",
  components: {
    DiscussionForm,
    TeamForm,
  },
  data() {
    return {
      tabList: [
        {
          icons: "../../static/icons/home.png",
          active: "../../static/icons/homeActive.png",
          name: "首页",
        },
        {
          icons: "../../static/icons/team.png",
          active: "../../static/icons/teamActive.png",
          name: "队伍",
        },
        {
          name: "center",
        },
        {
          icons: "../../static/icons/plan.png",
          active: "../../static/icons/planActive.png",
          name: "任务",
        },
        {
          icons: "../../static/icons/me.png",
          active: "../../static/icons/meActive.png",
          name: "我的",
        },
      ],
      tabIndex: 0,
      addState: false,
      showText: false,
      showDiscussionForm: false,
      showTeamForm: false,
    };
  },

  methods: {
    handleClick(index) {
      this.tabIndex = index;
      this.$emit("changeTab", index);
    },
    changeAddState() {
      this.tabIndex = -1;
      this.addState = !this.addState;
      this.addState ? this.$emit("hiddenOther") : this.$emit("showOther");
      this.showDiscussionForm = this.showDiscussionForm ? false : false;
    },
    showDiscussionFormView() {
      this.showDiscussionForm = true;
    },
  },
};
</script>

<style lang="scss" scoped>
.my-tab {
  position: fixed;
  bottom: 0;
  width: 100%;
  height: 120rpx;
  display: flex;
  align-items: center;
  justify-content: space-around;
  border-top-left-radius: 25rpx;
  border-top-right-radius: 25rpx;
  box-shadow: -2px 0 10px rgba(200, 200, 200, 0.7);
  background-color: #fff;
  .tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 22rpx;
    transition: all 0.3s;
    color: #aaa;
    .img {
      width: 50rpx;
      height: 50rpx;
    }
  }
  .tabActive {
    color: #05a47d;
    animation: tabAnimation 0.5s linear;
  }
  .center {
    margin: 0 30rpx;
  }
  .addBtn {
    position: absolute;
    left: 50%;
    top: -60rpx;
    transform: translateX(-50%) scale(1);
    width: 120rpx;
    height: 120rpx;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 50rpx;
    color: #05a47d;
    z-index: 15;
    box-shadow: 2px 2px 4px rgba(5, 164, 125, 0.3),
      -1px -1px 4px rgba(5, 164, 125, 0.3);
    background-color: #fff;
    transition: all 1s;
  }
  .addBtnActive {
    transform: translate(-50%, -200rpx) rotateZ(135deg) scale(1.3);
    box-shadow: none;
    font-weight: 700;
  }
  .addBtnHidden {
    display: none;
  }

  .createForm {
    position: fixed;
    opacity: 0;
    left: 50%;
    top: -100%;
    transform: translateX(-50%);
    width: 650rpx;
    height: 1100rpx;
    border-radius: 15rpx;
    background-color: #fff;
    transition: all 0.5s;
    z-index: -9999;
    box-shadow: 2rpx 2rpx 10rpx rgba(0, 0, 0, 0.3) inset;
  }
  .formActive {
    top: 10%;
    opacity: 1;
    z-index: 100000;
  }
  .teamFormActive {
    top: 5%;
    opacity: 1;
    z-index: 100000;
  }
  .create {
    position: absolute;
    width: 100rpx;
    height: 100rpx;
    background-color: #fff;
    border-radius: 50%;
    transition: all 1s;
    z-index: 14;
    transform: translateY(-60rpx) rotate(-90deg);
    box-shadow: 1px 1px 8px rgba(0, 0, 0, 0.3), -1px -1px 8px rgba(0, 0, 0, 0.3);
    opacity: 0;
  }
  .team {
    transform: translateY(-60rpx) rotate(180deg);
  }
  .comment {
    transform: translateY(-60rpx) rotate(-180deg);
  }

  .content {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: all 0.5s;
    letter-spacing: 2rpx;
    border-radius: 20rpx;
    image {
      width: 150rpx;
      height: 150rpx;
      margin-bottom: 30rpx;
    }
  }
  .contentActive {
    transition-delay: 1s;
    opacity: 1;
  }

  .teamActive {
    width: 300rpx;
    height: 300rpx;
    border-radius: 20rpx;
    transform: translate(-190rpx, -800rpx);
    opacity: 1;
  }
  .commentActive {
    width: 300rpx;
    height: 300rpx;
    border-radius: 20rpx;
    transform: translate(190rpx, -800rpx);
    opacity: 1;
  }

  .mask {
    position: fixed;
    transition: all 0.5s;
    opacity: 0;
  }
  .maskActive {
    width: 100vw;
    height: 100vh;
    opacity: 1;
    background-color: #05a47d;
    top: 0;
    z-index: 13;
  }
  @keyframes tabAnimation {
    0% {
      transform: scale(1);
    }
    50% {
      transform: scale(1.3);
    }
    100% {
      transform: scale(1);
    }
  }
}
</style>
